<@override name="content">
<style>
    .btn-outline{
        border:none;
    }
    .btn-outline:hover{
        background-color: #0e9aef;
        color: #fff;
    }
    .layui-form-item .layui-btn {
        margin-top: 5px;
        margin-right: 10px;
    }
    .layui-btn-primary{
        margin-right: 10px;
        margin-left: 0!important;
    }
    label{
        margin-bottom: 0!important;
        margin-top: 4px;
    }
</style>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15" id="app">
        <!--搜索条件-->
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">搜索条件</div>
                <div class="layui-card-body">
                    <div class="layui-carousel layadmin-carousel layadmin-shortcut" lay-anim="" lay-indicator="inside"
                         lay-arrow="none" style="background:none">
                        <div class="layui-card-body">
                            <div class="layui-row layui-col-space10 layui-form-item">
                                <div class="layui-col-lg12">
                                    <label class="layui-form-label">订单状态:</label>
                                    <input type="hidden" id="orderStatus"  v-model="where.status">
                                    <div class="layui-input-block" v-cloak="">
                                        <button class="layui-btn layui-btn-sm"
                                                :class="{'layui-btn-primary':where.status!==item.value}"
                                                @click="setStatus(item.value)" type="button"
                                                v-for="item in orderStatus">{{item.name}}
                                        </button>
                                    </div>
                                </div>
                                <div class="layui-col-lg12">
                                    <label class="layui-form-label">订单号:</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="keyWords" style="width: 50%" v-model="where.keyWords"
                                               placeholder="请输入姓名、电话、订单编号" class="layui-input" id="keyWords">
                                    </div>
                                </div>
                                <div class="layui-col-lg12">
                                    <div class="layui-input-block">
                                        <button @click="search" type="button"
                                                class="layui-btn layui-btn-sm layui-btn-normal">
                                            <i class="layui-icon layui-icon-search"></i>搜索
                                        </button>
                                        <button @click="refresh" type="reset"
                                                class="layui-btn layui-btn-primary layui-btn-sm">
                                            <i class="layui-icon layui-icon-refresh"></i>刷新
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--end-->
        <!-- 中间详细信息-->
        <#if userType?? && userType == '2'>
            <div class="layui-col-sm6 layui-col-md3">
                <div class="layui-card">
                    <div class="layui-card-header">
                        总收入
                        <span class="layui-badge layuiadmin-badge" class="item.background_color">${order.totalMoney!}</span>
                    </div>
                </div>
            </div>
        </#if>
        <!--enb-->
    </div>
    <!--列表-->
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">订单列表</div>
                <div class="layui-card-body">
                    <div class="layui-btn-container" id="container-action">
                        <button class="layui-btn layui-btn-sm" data-type="del_order">批量删除订单</button>
                        <button class="layui-btn layui-btn-sm" onclick="download(this)">导出</button>
                        <button class="layui-btn layui-btn-sm" onclick="print()">打印</button>
                    </div>
                    <table class="layui-hide" id="List" lay-filter="List"></table>
                    <!--订单-->
                    <script type="text/html" id="order_id">
                        {{d.order_id}}<br/>
                        <span style="color: {{d.color}};">{{d.pink_name}}</span><br/>　
                        {{#  if(d.is_del == 1){ }}<span style="color: {{d.color}};">用户已删除</span>{{# } }}　
                    </script>
                    <!--用户信息-->
                    <script type="text/html" id="userinfo">
                        {{d.nickName==null ? '暂无信息':d.nickName}}
                    </script>
                    <!--分销员信息-->
                    <script type="text/html" id="spread_uid">
                        {{# if(d.spread_uid != 0){ }}
                        <button class="btn-xs btn-outline" type="button"
                                onclick="$eb.createModalFrame('推荐人信息','/admin/order.StoreOrder/order_spread_user.html?uid={{d.spread_uid}}',{w:600,h:400})">
                            {{d.spread_nickname}}
                        </button>
                        {{# }else{ }}无{{# } }}
                    </script>
                    <!--支付状态-->
                    <script type="text/html" id="paid">
                        {{#  if(d.payPrice == null){ }}<span>未支付</span>{{# } }}　
                        {{#  if(d.payPrice != null){ }}<span>已支付</span>{{# } }}　
                    </script>
                    <!--订单状态-->
                    <script type="text/html" id="status">
                        {{#  if(d.status == 1){ }}<span>待付款</span>{{# } }}　
                        {{#  if(d.status == 2){ }}<span>待发货</span>{{# } }}　
                        {{#  if(d.status == 3){ }}<span>待收货</span>{{# } }}　
                        {{#  if(d.status == 4){ }}<span>待评价</span>{{# } }}　
                        {{#  if(d.status == 5){ }}<span>已完成</span>{{# } }}　
                        {{#  if(d.status == 7){ }}<span>退款中</span>{{# } }}　
                        {{#  if(d.status == 8){ }}<span>已退款</span>{{# } }}　
                    </script>
                    <script type="text/html" id="orderType">
                        {{#  if(d.orderType == 1){ }}<span>普通订单</span>{{# } }}　
                        {{#  if(d.orderType == 2){ }}<span>秒杀订单</span>{{# } }}　
                        {{#  if(d.orderType == 3){ }}<span>拼团订单</span>{{# } }}　
                        {{#  if(d.orderType == 4){ }}<span>积分订单</span>{{# } }}　
                    </script>
                    <!--商品信息-->
                    <script type="text/html" id="info">
                        <div>
                            <span>
                                <img style="width: 30px;height: 30px;margin:0;cursor: pointer;"
                                     src="{{d.image}}">
                            </span>
                            <span>{{d.goodsName}}&nbsp;{{d.goodsAttr}}</span>
                            <span> | ￥{{d.webSinglePrice}}×{{d.totalNum}}</span>
                        </div>
                    </script>

                    <script type="text/html" id="act">
                        <button class="layui-btn layui-btn-xs"
                                onclick="$eb.createModalFrame('订单详情','${request.contextPath}/admin/order/detail?id={{d.id}}')">
                            详情
                        </button>
                        <button type="button" class="layui-btn layui-btn-xs" onclick="dropdown(this)">操作 <span
                                class="caret"></span></button>
                        <ul class="layui-nav-child layui-anim layui-anim-upbit">
                            <li>
                                <a href="javascript:void(0);"
                                   onclick="$eb.createModalFrame('修改订单','${request.contextPath}/admin/order/modify?id={{d.id}}')">
                                     修改订单
                                </a>
                            </li>
                            <li>
                                <a href="javascript:void(0);" lay-event='delstor'>

                                    {{# if(d.status == 1){ }}
                                     取消订单
                                    {{# }else if(d.status == 2||d.status == 3||d.status == 4||d.status == 5||d.status == 6){ }} 申请退款{{# } }}
                                </a>
                            </li>
                            {{#  if(d.status == 7){ }}
                                <li>
                                    <a href="javascript:void(0);"
                                       onclick="$eb.createModalFrame('退款处理','${request.contextPath}/admin/order/refund?orderId={{d.orderId}}')">
                                       立即退款
                                    </a>
                                </li>
                                <li>
                                    <a href="javascript:void(0);"
                                       onclick="$eb.createModalFrame('拒绝退款原因','${request.contextPath}/admin/order/refused?orderId={{d.orderId}}')">
                                         拒绝退款
                                    </a>
                                </li>
                            {{# } }}　
                        </ul>
                    </script>
                </div>
            </div>
        </div>
    </div>
    <!--end-->
</div>
<script src="${request.contextPath}/js/layuiList.js"></script>
</@override>
<@override name="script">
<script>
    layList.tableList('List', "${request.contextPath}/admin/order/listData?orderType=${orderType}", function () {
        return [
            {type: 'checkbox'},
            {field: 'orderId', title: '订单号', sort: true, event: 'order_id', width: '17%', align: 'center'},
            {field: 'orderType', title: '订单类型', templet: '#orderType', width: '7%', align: 'center'},
            {field: 'nickName', title: '用户信息', templet: '#userinfo', width: '10%', align: 'center'},
            {field: 'info', title: '商品信息', templet: "#info", height: 'full-20'},
            {field: 'webPayPrice', title: '实际支付', width: '8%', align: 'center'},
            {field: 'paid', title: '支付状态', templet: '#paid', width: '8%', align: 'center'},
            {field: 'status', title: '订单状态', templet: '#status', width: '8%', align: 'center'},
            {field: 'createDate', title: '下单时间', width: '12%', align: 'center'},
            {field: 'right', title: '操作', align: 'center', toolbar: '#act', width: '13%'},
        ];
    });
    layList.tool(function (event, data, obj) {
        switch (event) {
            case 'order_paid':
                var url = layList.U({c: 'order.store_order', a: 'offline', p: {id: data.id}});
                $eb.$swal('delete', function () {
                    $eb.axios.get(url).then(function (res) {
                        if (res.status == 200 && res.data.code == 200) {
                            $eb.$swal('success', res.data.msg);
                        } else
                            return Promise.reject(res.data.msg || '修改失败')
                    }).catch(function (err) {
                        $eb.$swal('error', err);
                    });
                }, {'title': '您确定要修改支付状态吗？', 'text': '修改后将无法恢复,请谨慎操作！', 'confirm': '是的，我要修改'})
                break;
            case 'verify':
                var url = layList.U({c: 'order.store_order', a: 'verify', p: {id: data.id}});
                $eb.$swal('delete', function () {
                    $eb.axios.get(url).then(function (res) {
                        if (res.status == 200 && res.data.code == 200) {
                            $eb.$swal('success', res.data.msg);
                        } else
                            return Promise.reject(res.data.msg || '核销失败')
                    }).catch(function (err) {
                        $eb.$swal('error', err);
                    });
                }, {'title': '您确定核销该订单吗？', 'text': '修改后将无法恢复,请谨慎操作！', 'confirm': '是的，我要核销'})
                break;
            case 'marke':
                var url = layList.U({c: 'order.store_order', a: 'remark'}),
                    id = data.id,
                    make = data.remark;
                $eb.$alert('textarea', {title: '请修改内容', value: make}, function (result) {
                    if (result) {
                        $.ajax({
                            url: url,
                            data: 'remark=' + result + '&id=' + id,
                            type: 'post',
                            dataType: 'json',
                            success: function (res) {
                                if (res.code == 200) {
                                    $eb.$swal('success', res.msg);
                                } else
                                    $eb.$swal('error', res.msg);
                            }
                        })
                    } else {
                        $eb.$swal('error', '请输入要备注的内容');
                    }
                });
                break;
            case 'danger':
                var url = layList.U({c: 'order.store_order', a: 'take_delivery', p: {id: data.id}});
                $eb.$swal('delete', function () {
                    $eb.axios.get(url).then(function (res) {
                        if (res.status == 200 && res.data.code == 200) {
                            $eb.$swal('success', res.data.msg);
                        } else
                            return Promise.reject(res.data.msg || '收货失败')
                    }).catch(function (err) {
                        $eb.$swal('error', err);
                    });
                }, {'title': '您确定要修改收货状态吗？', 'text': '修改后将无法恢复,请谨慎操作！', 'confirm': '是的，我要修改'})
                break;
            case 'order_info':
                $eb.createModalFrame(data.nickName + '订单详情', '${request.contextPath}/admin/order/detail?id='+data.id);
                break;
            case 'delstor':
                var url = '${request.contextPath}/admin/order/delete';
                var ids = new Array();
                ids.push(data.id);
                var title = data.status==1?'您确定要删除订单吗？':'您确定要申请退款吗？';
                var text = data.status==1?'删除后将无法恢复,请谨慎操作！':'申请完毕请在退款中处理！';
                var confirm = data.status==1?'是的，我要删除':'是的，我要退款！';
                $eb.$swal('delete', function () {
                    $eb.axios.post(url, {ids: ids}).then(function (res) {
                        if (res.data.code == 200) {
                            $eb.$swal('success', res.data.msg);
                             location.reload();
                        } else
                            return Promise.reject(res.data.msg || '删除失败')
                    }).catch(function (err) {
                        $eb.$swal('error', err);
                    });
                }, {'title': title, 'text': text, 'confirm': confirm})
                break;
            case 'order_print':
                var url = layList.U({c: 'order.store_order', a: 'order_print', p: {id: data.id}});
                $eb.$swal('delete', function () {
                    $eb.axios.get(url).then(function (res) {
                        if (res.status == 200 && res.data.code == 200) {
                            $eb.$swal('success', res.data.msg);
                        } else
                            return Promise.reject(res.data.msg || '核销失败')
                    }).catch(function (err) {
                        $eb.$swal('error', err);
                    });
                }, {'title': '确认打印订单？', 'text': '是否确认打印！', 'confirm': '确定'})
                break;
        }
    })
    var action = {
        del_order: function () {
            var ids = layList.getCheckData().getIds('id');
            if (ids.length) {
                var url = '${request.contextPath}/admin/order/delete';
                $eb.$swal('delete', function () {
                    $eb.axios.post(url, {ids: ids}).then(function (res) {
                        if (res.data.code == 200) {
                            $eb.$swal('success', res.data.msg);
                             location.reload();
                        } else
                            return Promise.reject(res.data.msg || '删除失败')
                    }).catch(function (err) {
                        $eb.$swal('error', err);
                    });
                }, {'title': '您确定要删除订单吗？', 'text': '删除后将无法恢复,请谨慎操作！', 'confirm': '是的，我要删除'})
            } else {
                layList.msg('请选择要删除的订单');
            }
        },
        write_order: function () {
            return $eb.createModalFrame('订单核销', layList.U({a: 'write_order'}), {w: 500, h: 400});
        },
    };
    $('#container-action').find('button').each(function () {
        $(this).on('click', function () {
            var act = $(this).data('type');
            action[act] && action[act]();
        });
    })
    //下拉框
    $(document).click(function (e) {
        $('.layui-nav-child').hide();
    })
    function download(that){
        window.location.href='${request.contextPath}/admin/order/download?orderType=${orderType}&keyWords='+$("#keyWords").val()+'&status='+$("#orderStatus").val();
    }
    function print(){
          let  u = window.open("打印窗口", "_blank"),
             h = ["<style>", "body{font-size: 12px; color: #666;}", "table{width: 100%; border-collapse: collapse; border-spacing: 0;}", "th,td{line-height: 20px; padding: 9px 15px; border: 1px solid #ccc; text-align: left; font-size: 12px; color: #666;}", "a{color: #666; text-decoration:none;}", "*.layui-hide{display: none}", "</style>"].join("");
             u.document.write(h + $(".layui-table-box").prop("outerHTML")),
            u.document.close(),
            u.print(),
            u.close()

    }
    function dropdown(that) {
        var oEvent = arguments.callee.caller.arguments[0] || event;
        oEvent.stopPropagation();
        var offset = $(that).offset();
        var top = offset.top - $(window).scrollTop();
        var index = $(that).parents('tr').data('index');
        $('.layui-nav-child').each(function (key) {
            if (key != index) {
                $(this).hide();
            }
        })
        if ($(document).height() < top + $(that).next('ul').height()) {
            $(that).next('ul').css({
                'padding': 10,
                'top': -($(that).parents('td').height() / 2 + $(that).height() + $(that).next('ul').height() / 2),
                'min-width': 'inherit',
                'position': 'absolute'
            }).toggle();
        } else {
            $(that).next('ul').css({
                'padding': 10,
                'top': $(that).parents('td').height() / 2 + $(that).height(),
                'min-width': 'inherit',
                'position': 'absolute'
            }).toggle();
        }
    }

    var real_name = '';
    var orderCount ={"ys":153,"wz":345,"wf":4,"ds":61,"dp":66,"jy":12,"tk":17,"yt":104,"del":101,"write_off":10,"general":621,"pink":83,"seckill":7,"bargain":9}, payTypeCount ={"weixin":489,"yue":114,"offline":117},
        status ='';
    require(['vue'], function (Vue) {
        new Vue({
            el: "#app",
            data: {
                badge: [],
                orderType: [
                    {name: '全部', value: ''},
                    {name: '普通订单', value: 1},
                    {name: '拼团订单', value: 3},
                    {name: '秒杀订单', value: 2},
                ],
                orderStatus: [
                    {name: '全部', value: ''},
                    {name: '待付款', value: 1},
                    {name: '待发货', value: 2},
                    {name: '待收货', value: 3},
                    {name: '待评价', value: 4},
                    {name: '已完成', value: 5},
                    {name: '退款中', value: 7},
                    {name: '已退款', value: 8}
                ],
                where: {
                    status: status,
                    orderType: '',
                    keyWords: real_name || '',
                },
                showtime: false,
            },
            watch: {
            },
            methods: {
                setData: function (item) {
                    var that = this;
                    if (item.is_zd == true) {
                        that.showtime = true;
                        this.where.data = this.$refs.date_time.innerText;
                    } else {
                        this.showtime = false;
                        this.where.data = item.value;
                    }
                },
                setStatus:function(status){
                     this.where.status = status
                     layList.reload(this.where, true);
                },
                getBadge: function () {
                    var that = this;
                    layList.basePost(layList.Url({c: 'order.store_order', a: 'getBadge'}), this.where, function (rem) {
                        that.badge = rem.data;
                    });
                },
                search: function () {
                    this.where.excel = 0;
                    layList.reload(this.where, true);
                },
                refresh: function () {
                    layList.reload();
                },
                excel: function () {
                    this.where.excel = 1;
                    location.href = layList.U({c: 'order.store_order', a: 'order_list', q: this.where});
                    this.where.excel = 0;
                }
            },
            mounted: function () {
                var that = this;
                window.formReload = this.search;
                layList.laydate.render({
                    elem: this.$refs.date_time,
                    trigger: 'click',
                    eventElem: this.$refs.time,
                    range: true,
                    change: function (value) {
                        that.where.data = value;
                    }
                });
            }
        })
    });
</script>


</@override>
<@extends name="../public/container.html"/>